package com.ciquan.server.util.json;

import com.ciquan.server.util.DateUtils;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

import java.io.IOException;
import java.util.Date;

/**
 * Created by kakalee on 14-10-14.
 */
public class DateJsonSerializer extends JsonSerializer<Date> {

    @Override
    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
        if(date != null) {
            jsonGenerator.writeString(DateUtils.formatToString(date, DateUtils.yyyyMMddHHmmss));
        } else {
            jsonGenerator.writeString("");
        }

    }
}
